<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>交易市场</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="../bower_components/font-awesome/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="../bower_components/Ionicons/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="../dist/css/AdminLTE.css">
  <!-- AdminLTE Skins. We have chosen the skin-blue for this starter
        page. However, you can choose any other skin. Make sure you
        apply the skin class to the body tag so the changes take effect. -->
  <link rel="stylesheet" href="../dist/css/skins/skin-blue.min.css">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

  <!-- Google Font -->
  <link rel="stylesheet" href="https://fonts.useso.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
  <link rel="stylesheet" href="../dist/css/mycss.css">
  <!-- Animate.css -->
  <link rel="stylesheet" href="../css/animate.css">
  <!-- Icomoon Icon Fonts-->
  <link rel="stylesheet" href="../css/icomoon.css">
  <!-- Bootstrap  -->
  <link rel="stylesheet" href="../css/bootstrap.css">
  <!-- Superfish -->
  <link rel="stylesheet" href="../css/superfish.css">

  <link rel="stylesheet" href="../css/style.css">


  <!-- Modernizr JS -->
  <script src="../js/modernizr-2.6.2.min.js"></script>
  <!-- FOR IE9 below -->
  <!--[if lt IE 9]>
	<script src="js/respond.min.js"></script>
	<![endif]-->
  <!-- jQuery -->


  <script src="../js/jquery.min.js"></script>
  <!-- jQuery Easing -->
  <script src="../js/jquery.easing.1.3.js"></script>
  <!-- Bootstrap -->
  <script src="../js/bootstrap.min.js"></script>
  <!-- Waypoints -->
  <script src="../js/jquery.waypoints.min.js"></script>
  <!-- Stellar -->
  <script src="../js/jquery.stellar.min.js"></script>
  <!-- Superfish -->
  <script src="../js/hoverIntent.js"></script>
  <script src="../js/superfish.js"></script>

  <!-- Main JS -->
  <script src="../js/main.js"></script>
  <script src="../dist/js/myjs.js"></script>
</head>
<!--
BODY TAG OPTIONS:
=================
Apply one or more of the following classes to get the
desired effect
|---------------------------------------------------------|
| SKINS         | skin-blue                               |
|               | skin-black                              |
|               | skin-purple                             |
|               | skin-yellow                             |
|               | skin-red                                |
|               | skin-green                              |
|---------------------------------------------------------|
|LAYOUT OPTIONS | fixed                                   |
|               | layout-boxed                            |
|               | layout-top-nav                          |
|               | sidebar-collapse                        |
|               | sidebar-mini                            |
|---------------------------------------------------------|
-->

<body class="hold-transition skin-blue sidebar-mini">
  <div class="wrapper">

    <!-- Main Header -->
    <header class="main-header">
    </header>
    <!-- Left side column. contains the logo and sidebar -->
    <aside class="main-sidebar">
      <!-- /.sidebar -->
    </aside>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
      <!-- Content Header (Page header) -->
      <section class="content-header">
        <h1>
          首页
          <small>>用户中心>交易市场>搜索结果</small>
        </h1>
      </section>

      <!-- Main content -->
      <section class="content container-fluid">

        <!--------------------------
        | Your Page Content Here |
        -------------------------->
        <!--coded By Bobo 2017/7/13-->
        <div class="box">
          <div class="box-body">

            <div>
              <!-- Nav tabs -->


              <!-- Tab panes -->
              <div class="tab-content">

                <div role="tabpanel" class="tab-pane active">
                  <table class="table table-hover c">
                    <tr>
                      <div id="search11">
                        <div id="searchResult">
                          <script type="text/javascript">
                            //           $(document).ready(function(){
                            function getCookie(objName) {//获取指定名称的cookie的值   
                              var arrStr = document.cookie.split("; ");
                              for (var i = 0; i < arrStr.length; i++) {
                                var temp = arrStr[i].split("=");
                                if (temp[0] == objName)
                                  return unescape(temp[1]);
                              }
                            }
                            var name = getCookie("name");
                            if (name == "") {
                              window.location.href = "login.html";
                            }
                            $("#name").html(name);
                            var thisURL = document.URL;
                            var getval = thisURL.split('?')[1];
                            var type = getval.split("=")[1];
                            var postBody = {
                              type: type
                            };
                            $.ajax({
                              type: 'POST',
                              url: '/check/unsold/query/by_type/',
                              data: postBody,
                              dataType: 'json',
                              success: function (data) {
                                //$("暂无满足要求的数据").appendTo("#searchResult");
                                console.log("ajax" + JSON.stringify(data));
                                function getJsonLength(jsonData) {
                                  var jsonLength = 0;
                                  for (var item in jsonData) {
                                    jsonLength++;
                                  }
                                  return jsonLength;
                                }
                                var jsonLength = getJsonLength(data);
                                for (var o in data) {
                                  $('<br><strong>&nbsp&nbsp&nbsp&nbsp资产发行申请单号:</strong><span id="_id' + o + '">' + data[o]._id +
                                    '</span><strong>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp;价值:</strong><span id="money' + o + '">' + data[o].money +
                                    '</span><strong>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp;所有者:</strong><span id="userId' + o + '">' + data[o].userId +
                                    '</span><br><strong>&nbsp&nbsp&nbsp&nbsp;品名:</strong><span id="pinming' + o + '">' + data[o].pinming +
                                    '</span><strong>&nbsp&nbsp&nbsp&nbsp;数量:</strong><span id="shuliang' + o + '">' + data[o].shuliang +
                                    '</span><strong>&nbsp&nbsp&nbsp&nbsp;电子仓单编号:</strong><span id="cangdanId' + o + '">' + data[o].cangdanId +
                                    '</span><strong>&nbsp&nbsp&nbsp&nbsp;规格:</strong><span id="guige' + o + '">' + data[o].guige +
                                    '</span><strong>&nbsp&nbsp&nbsp&nbsp;重量:</strong><span id="zhongliang' + o + '">' + data[o].zhongliang +
                                    '</span><strong>&nbsp&nbsp&nbsp&nbsp;材质:</strong><span id="caizhi' + o + '">' + data[o].caizhi +
                                    '</span><strong>&nbsp&nbsp&nbsp&nbsp;产地:</strong><span id="chandi' + o + '">' + data[o].chandi +
                                    '</span><strong>&nbsp&nbsp&nbsp&nbsp;件数:</strong><span id="jianshu' + o + '">' + data[o].jianshu +
                                    '</span><strong>&nbsp&nbsp&nbsp&nbsp;类型:</strong><span id="type' + o + '">' + data[o].type +
                                    '</span><strong>&nbsp&nbsp&nbsp&nbsp;交割仓库:</strong><span id="cangku' + o + '">' + data[o].cangku +
                                    '</span><br><button class="btn btn-default pull-right" id="' + o + '" onclick="buy(this)">购买</button></br></hr>').appendTo("#searchResult");
                                }
                                if (jsonLength == 0) {
                                  $("#searchResult").html("暂无满足要求的数据,请稍后再试");
                                }
                              }
                            }).error(function (err) {
                              console.log(err);
                              alert(err.responseText);
                            });
  //             });
                          </script>
                        </div>
                      </div>
                    </tr>
                  </table>
                </div>
              </div>


            </div>
          </div>
          <!-- /.box-body -->
        </div>
      </section>
      <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->

    <!-- Main Footer -->
    <footer class="main-footer">
    </footer>
    <!-- Control Sidebar -->
    <aside class="control-sidebar control-sidebar-dark">
      <!-- Create the tabs -->
      <ul class="nav nav-tabs nav-justified control-sidebar-tabs">
        <li class="active"><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li>
        <li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i class="fa fa-gears"></i></a></li>
      </ul>
      <!-- Tab panes -->
      <div class="tab-content">
        <!-- Settings tab content -->
        <div class="tab-pane" id="control-sidebar-settings-tab">
          <form method="post">
            <h3 class="control-sidebar-heading">General Settings</h3>

            <div class="form-group">
              <label class="control-sidebar-subheading">
              Report panel usage
              <input type="checkbox" class="pull-right" checked>
            </label>

              <p>
                Some information about this general settings option
              </p>
            </div>
            <!-- /.form-group -->
          </form>
        </div>
        <!-- /.tab-pane -->
      </div>
    </aside>
    <!-- /.control-sidebar -->
    <!-- Add the sidebar's background. This div must be placed
  immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
  </div>
  <!-- ./wrapper -->

  <!-- REQUIRED JS SCRIPTS -->

  <!-- jQuery 3 -->
  <script src="../bower_components/jquery/dist/jquery.min.js"></script>
  <!-- Bootstrap 3.3.7 -->
  <script src="../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
  <!-- AdminLTE App -->
  <script src="../dist/js/adminlte.js"></script>
  <script src="../dist/js/myjs.js"></script>
  <!-- Optionally, you can add Slimscroll and FastClick plugins.
     Both of these plugins are recommended to enhance the
     user experience. -->
  <script>
                /*
               *加载header、sider和footer
              */
                $(".main-header").load("mainheader.html");
                $(".main-sidebar").load("mainsider.html");
                $(".main-footer").load("../mainfooter.html");
/*
*
*/
  </script>
  <script type="text/javascript">
   		function buy(obj) {
        var num = obj.id;
        // data(id);
        $('#' + num + '').replaceWith('<span class="pull-right" style="color:#00bfff;">购买成功</span>');
        var name = getCookie("name");
        if (name == "") {
          window.location.href = "login.html";
        }
        // $("#name").html(name);
        var istr = "#_id" + num;
        // //var pstr = "#state" + num;
        var hstr = "#userId" + num;
        alert($("#name").html());
        // var rstr = "#disease1" + num;
        // alert($(istr).html());
        var postBody = {
  //				coreDataId: $(istr).html(),
          
          bianhao:$(istr).html(),
          //	state: $(pstr).html(),
          useId: $(hstr).html(),
          // type: $(rstr).html(),
          buyer: $("#name").html()
        };
        console.log(JSON.stringify(postBody));
  
        $.ajax({
          type: 'POST',
          url: '/check/buy/application',
          data: postBody,
          dataType: 'json',
          success: function (data) {
            var jsonstr = JSON.stringify(data);
            alert("请求成功！正在等待受理");
            console.log("data success" + jsonstr);
  
          }
        }).error(function (err) {
          console.log(err);
          alert("服务器忙！请稍后再尝试");
        });
      }
    document.getElementById('name').innerHTML = name;
    function login_out() {
      delCookie(getCookie("name"));
      setTimeout("window.location.href='login.html'", 1000);
    }
    function delCookie(name) {//为了删除指定名称的cookie，可以将其过期时间设定为一个过去的时间   
      var date = new Date();
      date.setTime(date.getTime() - 10000);
      document.cookie = name + "=a; expires=" + date.toGMTString();
    }
  </script>
</body>

</html>